package com.techfengs.test13;

import java.io.ObjectOutputStream.PutField;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * [老马书城集合版]
 * 项目功能：
 * 1. 展示书籍
 * 2. 上新书籍
 * 3. 下架书籍
 * 4. 退出应用
 */
public class Test {
	public static void main (String[] args) {
		// 借助Scanner类：
		Scanner sc = new Scanner(System.in);

		// 创建一个集合：用于存放相同的个体
		ArrayList list = new ArrayList();
		while (true) {
			// 打印菜单
			System.out.print("------------------------------");
			System.out.print("欢迎来到老马书城");
			System.out.println("------------------------------");
			System.out.println("1. 展示书籍");
			System.out.println("2. 上新书籍");
			System.out.println("3. 下架书籍");
			System.out.println("4. 退出应用");

			// 提示用户输入信息
			System.out.println("请输入你想要执行的功能对应的序号：");
			int index = sc.nextInt();

			// 根据用户录入的序号进行后续判断
			if (index == 1) {
				System.out.println("[老马书城]>>>>>>>>>>>>>>>>>>>>1. 展示书籍");


				System.out.println("书籍编号\t" + "书籍名称\t" + "书籍作者");
				for (int i = 0; i < list.size(); i++) {
					Book b = (Book)list.get(i);
					System.out.println(b.getBNo() + "\t" + b.getBName() + "\t" + b.getBAuthor());
				}
				System.out.println("");
			} else if (index == 2) {
				System.out.println("[老马书城]>>>>>>>>>>>>>>>>>>>>2. 上新书籍");
				// 从键盘录入书籍编号
				System.out.println("请录入书籍编号：");
				int bNo = sc.nextInt();
				System.out.println("请录入书籍名称：");
				String bName = sc.next();
				System.out.println("请录入书籍作者：");
				String bAuthor = sc.next();
				// 每上新一本书籍，就要创建一个书籍对象
				Book b = new Book();
				b.setBNo(bNo);
				b.setBName(bName);
				b.setBAuthor(bAuthor);
				list.add(b);
			} else if (index == 3) {
				System.out.println("[老马书城]>>>>>>>>>>>>>>>>>>>>3. 下架书籍");
				System.out.println("请录入你要下架的书籍编号");
				int bNo = sc.nextInt();
				for (int i = 0; i < list.size(); i++) {
					Book b = (Book)list.get(i);
					if ( b.getBNo() == bNo ) {
						list.remove(i);
						System.out.println("书籍编号为：" + bNo + "下架成功");
						break;
					}
				}
			} else if (index == 4) {
				System.out.println("[老马书城]<<<<<<<<<<<<<<<<<<<<4. 退出应用");
				break;
			} else {
				System.out.println("输入无效, 请重新输入正确的序号");
			}
		}
	}
}
